Telegram Group & Telegram Channel
🚀 HybridCache

Это решение давней проблемы с разделением между IMemoryCache и IDistributedCache.

🔧 Что даёт HybridCache:
• Единый API для in-memory и distributed кэша
• Настраиваемая сериализация
• Stampede protection (анти-нагрузочная защита)
• Удаление по тегам

🧠 Как работает GetOrCreateAsync:
1. Проверяет локальный и распределённый кэш
2. Если нет — вызывает фабричный метод
3. Кэширует результат и возвращает его

🛡️ Stampede protection: только один запрос на ключ запускает фабрику, остальные ждут — никакой гонки или перегрузки БД.

📌 Сниппет на .NET 9 выглядит так:


app.MapGet("/products/{id}", async (
int id,
HybridCache cache,
ProductDbContext db,
CancellationToken ct) =>
{
var product = await cache.GetOrCreateAsync(
$"product-{id}",
async token =>
{
return await db.Products
.Include(p => p.Category)
.FirstOrDefaultAsync(p => p.Id == id, token);
},
cancellationToken: ct
);

return product is null ? Results.NotFound() : Results.Ok(product);
});


HybridCache доступен для ASP.NET Core

Все разработчики могут воспользоваться HybridCache для более эффективного управления кэшем в приложениях на ASP.NET Core.



tg-me.com/csharp_ci/1386
Create:
Last Update:

🚀 HybridCache

Это решение давней проблемы с разделением между IMemoryCache и IDistributedCache.

🔧 Что даёт HybridCache:
• Единый API для in-memory и distributed кэша
• Настраиваемая сериализация
• Stampede protection (анти-нагрузочная защита)
• Удаление по тегам

🧠 Как работает GetOrCreateAsync:
1. Проверяет локальный и распределённый кэш
2. Если нет — вызывает фабричный метод
3. Кэширует результат и возвращает его

🛡️ Stampede protection: только один запрос на ключ запускает фабрику, остальные ждут — никакой гонки или перегрузки БД.

📌 Сниппет на .NET 9 выглядит так:


app.MapGet("/products/{id}", async (
int id,
HybridCache cache,
ProductDbContext db,
CancellationToken ct) =>
{
var product = await cache.GetOrCreateAsync(
$"product-{id}",
async token =>
{
return await db.Products
.Include(p => p.Category)
.FirstOrDefaultAsync(p => p.Id == id, token);
},
cancellationToken: ct
);

return product is null ? Results.NotFound() : Results.Ok(product);
});


HybridCache доступен для ASP.NET Core

Все разработчики могут воспользоваться HybridCache для более эффективного управления кэшем в приложениях на ASP.NET Core.

BY C# (C Sharp) programming




Share with your friend now:
tg-me.com/csharp_ci/1386

View MORE
Open in Telegram


C C Sharp programming Telegram | DID YOU KNOW?

Date: |

How Does Telegram Make Money?

Telegram is a free app and runs on donations. According to a blog on the telegram: We believe in fast and secure messaging that is also 100% free. Pavel Durov, who shares our vision, supplied Telegram with a generous donation, so we have quite enough money for the time being. If Telegram runs out, we will introduce non-essential paid options to support the infrastructure and finance developer salaries. But making profits will never be an end-goal for Telegram.

What is Telegram?

Telegram is a cloud-based instant messaging service that has been making rounds as a popular option for those who wish to keep their messages secure. Telegram boasts a collection of different features, but it’s best known for its ability to secure messages and media by encrypting them during transit; this prevents third-parties from snooping on messages easily. Let’s take a look at what Telegram can do and why you might want to use it.

C C Sharp programming from us


Telegram C# (C Sharp) programming
FROM USA